package vn.personal.anhht.bloback12.adapter;

import java.util.ArrayList;

import vn.personal.anhht.bloback12.activity.R;
import vn.personal.anhht.bloback12.bean.BlackObject;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class BlackListAdapter extends ArrayAdapter<BlackObject> {

    public ArrayList<BlackObject> items;
    private int selectedCounter = 0;
    public Context context;
    public BlackListAdapter(Context context, int textViewResourceId,
            ArrayList<BlackObject> items) {
        super(context, textViewResourceId, items);
        this.items = items;
        this.context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        
        View v = convertView;
        LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.custom_row_blacklist, null);
        final BlackObject item = items.get(position);
        if (item != null) {
            TextView tvName = (TextView) v.findViewById(R.id.tv_name);
            tvName.setText(item.getName());
            TextView tvPhone = (TextView) v.findViewById(R.id.tv_phone);
            tvPhone.setText(item.getPhone());
            if(item.getIsShowIv1() == 1){
                ImageView iv1 = (ImageView) v.findViewById(R.id.iv1);
                iv1.setVisibility(View.VISIBLE);
                Log.e("11111", "11111111111");
            }
            if(item.getIsShowIv2() == 1){
                ImageView iv2 = (ImageView) v.findViewById(R.id.iv2);
                iv2.setVisibility(View.VISIBLE);
                Log.e("22222", "2222222");
            }
            if(item.getIsShowIv3() == 1){
                ImageView iv3 = (ImageView) v.findViewById(R.id.iv3);
                iv3.setVisibility(View.VISIBLE);
            }
            /*CheckBox cbSelect = (CheckBox) v.findViewById(R.id.cb_select);
            cbSelect.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    CheckBox cbox = (CheckBox) v.findViewById(R.id.cb_select);
                    if (cbox.isChecked()) {
                        item.setSelected(true);
                        selectedCounter += 1;
                        // Toast.makeText(v.getContext(), selectedItems.size() +
                        // "__sdfaf" + item.getName(),
                        // Toast.LENGTH_SHORT).show();
                    } else {
                        item.setSelected(false);
                        selectedCounter -= 1;
                        // Toast.makeText(v.getContext(), selectedItems.size() +
                        // "__sdfaf" + item.getPhone(),
                        // Toast.LENGTH_SHORT).show();
                    }
                }
            });*/
        }
        return v;
    }

    public void setselectedCounter(int i) {
        selectedCounter = i;
    }

    public int getSelectedCounter() {
        return selectedCounter;
    }
}
